﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Medianamik.Core.DAL.SQL
{
    public class RowNumberSelectClause : SelectClause, ISqlQueryPart 
    {
        public OrderByClause OrderByClause
        {
            get; private set;
        }
        public RowNumberSelectClause(OrderByClause pOrderBy, Column pColumn)
            :base(pColumn)
        {
            OrderByClause = pOrderBy;
        }

        #region ISqlQueryPart Members

        public override StringBuilder ToSQL()
        {
            var select = new StringBuilder("SELECT ROW_NUMBER() OVER( ")
                .Append(OrderByClause.ToSQL())
                .Append(" ) as rownum, ")
                .Append(GetColumnList());

            return select;
        }

        #endregion
    }
}
